//e
#Title[Tv2]
#Text[]
#Image[]
#BGM[]
#Player[FREE]
#PlayLevel[]
#BackGround[]
#ScriptVersion[2]

script_enemy_main {

    // ֐̎荞
    #include_function ".\usershot\lib_usershot.txt"	// ew萔ǂݍ
    #include_function ".\effectdata\Obj_EffectALL.txt"	// GtFNg֐ꊇǂݍ

    // XNvg܂ł̃pX̎擾
    let csd        = GetCurrentScriptDirectory();

    // G摜̃pX
    let imgBoss    = csd ~ "img\ExRumia.png";

    // G̖O摜̃pX
    let ename      = csd ~ "img\ename.png";

    // ʒu̐ݒ
    let xIni       = GetCenterX()  + 1;
    let yIni       = GetClipMinY() + 120;

    // e摜̃pX
    let shotData   = csd ~ "\usershot\data_usershot.txt";

    @Initialize {

	LoadGraphic(imgBoss);
	SetTexture(imgBoss);

	SetLife(400);
	SetTimer(60);
	SetDamageRate(0,0);

	DrawTimer();				// c莞Ԃ̕\
	DrawTimerEx(3);				// c莞Ԃ̕\
	EnemyMarker01();			// Gl~[}[J[̕\
	LifeBar_A_02(1, 0.4, 0.2, false);	// Q[W̕\
	LifeBar_B_02(3, 0.2, 0.0, false);	// ԃQ[W̕\

	LifeStockBar(1);			// cXyJ[h̕\
	LifeStock(1,true);			// cXyJ[h̕\
	LifeCircleBar_A(0.4, 0.2, false);	// 2{ڂ̉~Q[W̕\
	LifeCircleBar_B(0.2, 0.0, false);	// 3{ڂ̉~Q[W̕\
	LifeCircleBar_Marker(0.8);		// 2ڂ̋؂̕\

	DrawEnemyName(ename,0,16,false);	// G̖O̕\
	Aura1(8, 64, 64,128);			// I[̕\1
	Aura2(0,160, 64, 64);			// I[̕\2
	MagicCircleEx2(false);			// @w̕\

	MagicCircle(false);
	SetRateScoreSystemEnable(false);
	LoadUserShotData(shotData);
	SetEffectForZeroLife(0, 0, 0);
	SetShotAutoDeleteClip(64, 64, 64, 64);

	MainTask();

    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 32);

	yield;
    }

    @DrawLoop {
	DrawGraphic(GetX, GetY);
    }

    @Finalize {
	//DeleteGraphic(imgBoss);
    }

    // C^XN
    task MainTask {

	yield;

	StandBy();
	Shot();
	loop {
	    wait(60);
	    Shot2();
	    Move();
        }

    }

    // ʒuֈړ
    function StandBy {
	SetMovePositionRandom01(416, 464, 5, xIni, yIni, xIni, yIni);
	SetGraphicMove();
	wait(60);
	SetGraphicStop();
	wait(60);
	SetDamageRate(20,0);
	SetGraphicPose();
    }

    // ړ
    function Move {
	SetMovePositionRandom01(60, 10, 3, xIni-120, yIni-30, xIni+120, yIni+30);
	SetGraphicMove();
	wait(60);
	SetGraphicStop();
    }

    // U
    task Shot {

	let way      = 2;			// e
	let long     = 80;			// G̋
	let speed    = 0.00;			// x
	let angle    = 0;			// 1ڂ̊px
	let addangle = 0.00;			// px
	let addspeed = 0.05;			// x
	let maxspeed = 0.00;			// ōx(Œᑬx)
	let delay    = 12;			// x

	let eff     = dYELLOW03;		// GtFNg̒萔(ID)
	let graphic = US_BALL_L_YELLOW;		// e摜̒萔
	let bomb    = false;			// {ϐ
	let time    = 100;			// RŎ

	loop {
	    loop(way) {
		CreateObjShotC_T01(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, angle, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
		angle += 360/way;
	    }
	    angle += 360/way/8;
	    if(GetTimer>39) { wait(5); }
	    wait(3);
	}
    }

    // U2
    function Shot2 {

	SetGraphicPose;

	let nam      = 12;			// e
	let long     = 10;			// G̋
	let speed    = 0.50;			// x
	let angle    = GetAngleToPlayer;	// px
	let addangle = 0.00;			// px
	let addspeed = 0.00;			// x
	let maxspeed = 0.00;			// ōx(Œᑬx)
	let delay    = 12;			// x

	let eff     = dGREEN13;			// GtFNg̒萔(ID)
	let graphic = US_RICE_M_GREEN;		// e摜̒萔
	let bomb    = false;			// {ϐ
	let time    = 0;			// RŎ

	loop(nam) {
	    CreateObjShotC_T02(GetX()+long*cos(angle)   , GetY()+long*sin(angle)   , speed, angle   , addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
	    CreateObjShotC_T02(GetX()+long*cos(angle+20), GetY()+long*sin(angle+20), speed, angle+20, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
	    CreateObjShotC_T02(GetX()+long*cos(angle-20), GetY()+long*sin(angle-20), speed, angle-20, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
	    speed += 5/nam;
	    wait(3);
	}
    }

    // OtBbN̐ݒ
    sub SetGraphicStop  { SetGraphicRect(  0,  0, 64, 64); }
    sub SetGraphicPose  { SetGraphicRect( 64,  0,128, 64); }
    sub SetGraphicLeft  { SetGraphicRect(128,  0,192, 64); }
    sub SetGraphicRight { SetGraphicRect(192,  0,256, 64); }

    sub SetGraphicMove {
	if(GetSpeedX <  0) { SetGraphicLeft(); }
	else { SetGraphicRight(); }
    }

    // w t[ҋ@
    function wait(w) { loop(w){ yield; } }

}